package com.salon.client.beans;

import java.util.Date;

import com.google.gwt.i18n.client.DateTimeFormat;

public class MasterBean extends ParentBean implements Comparable<MasterBean>{
	private String name;
	private String surname;
	private String lastName;
	private Date dob;
	private String address;
	private String phone;
	private int salary;
	private int percent;
	private float currentSalary;
	
	public float getCurrentSalary() {
		return currentSalary;
	}
	public void setCurrentSalary(float currentSalary) {
		this.currentSalary = currentSalary;
	}
	public int getSalary() {
		return salary;
	}
	public void setSalary(int salary) {
		this.salary = salary;
	}
	public int getPercent() {
		return percent;
	}
	public void setPercent(int percent) {
		this.percent = percent;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSurname() {
		return surname;
	}
	public void setSurname(String surname) {
		this.surname = surname;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public Date getDob() {
		return dob;
	}
	public void setDob(Date dob) {
		this.dob = dob;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	public String getAge() {
		if (dob == null) {
			return null;
		}
		Date now = new Date();
		Integer fullAge = null;
		int age = now.getYear() - dob.getYear();
		if (now.getMonth() > dob.getMonth()) {
			fullAge = age;
		}
		else if (now.getMonth() < dob.getMonth()) {
			-- age;
			fullAge = age;
		}
		else if (now.getMonth() == dob.getMonth()) {
			if (now.getDate() >= dob.getDate()) {
				fullAge = age;
			}
			else {
				-- age;
				fullAge = age;
			}
		}
		
		DateTimeFormat format = DateTimeFormat.getFormat("dd.MM.yyyy");
		String ageDesc = format.format(dob);
		ageDesc += " (полных - " + fullAge + ")";
		return ageDesc;
	}
	
	public String getMasterName() {
		String res = surname;
		if (name != null) {
			res += " " + name;
		}
		return res;
	}
	
	public String getNiceName() {
		String res = this.surname;
		if (name != null) {
			res += " " + this.name;
		}
		if (lastName != null) {
			res += " " + this.lastName;
		}
		return res;
	}
	@Override
	public int compareTo(MasterBean o) {
		return this.surname.compareTo(o.surname);
		
	}
}
